import { reactive, ref } from "vue";
import { getListApi } from "@/api/configCenter/outBoundAgent/index";
export default function InitHook() {
  //表单数据
  const formState = reactive<Partial<CustomerServiceWaybill.addOutOfWarehouse>>({
    outWarehouseBrokerId: undefined, //	出仓代理的id
    outWarehouseBrokerName: undefined
    // isTransferBill: 0 //是否转运单
  });

  //表格数据
  const tableData = reactive([]);

  //等待状态
  const loading = ref<boolean>(false);

  //表单ref
  const formRef = ref(null);
  const agentOptions = ref<Array<Base.GeneraDataType>>([]);

  //获取代理
  const agentOptionsApi = () => {
    getListApi({ pageNum: 1, pageSize: 999, beforePageNum: 0, name: "", total: 0, status: undefined }).then((res: any) => {
      const { data, code } = res;
      const { records } = data;
      if (code === 200) {
        agentOptions.value = records.map((t: any) => {
          return { label: t.name, value: t.id };
        });
      }
    });
  };
  return {
    tableData,
    formState,
    loading,
    formRef,
    agentOptionsApi,
    agentOptions
  };
}
